package com.quanquan.management.service;

import com.quanquan.management.core.service.GenericService;
import com.quanquan.management.entity.SysRoleUser;
import com.quanquan.management.repository.SysRoleUserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import java.util.List;


@Service
public class SysRoleUserService extends GenericService<SysRoleUser, String> {

    @Autowired
    private SysRoleUserRepository sysRoleUserRepository;

    @PostConstruct
    private void init() {
        setGenericRepository(sysRoleUserRepository);
    }

    public SysRoleUser findByUserId(String userId) {
        List<SysRoleUser> byUserId = sysRoleUserRepository.findByUserId(userId);
        if (null != byUserId && byUserId.size() > 0) {
            return sysRoleUserRepository.findByUserId(userId).get(0);
        }
        return null;
    }

}
